package main

import (
	"fmt"
)

//append()为切片追加元素
func main() {
	s1 := []string{"广州", "北京"}
	fmt.Printf("s1=%v len(s1)=%d cap(s1)=%d\n", s1, len(s1), cap(s1))
	s2 := append(s1[:1], "上海", "上海") //append追加元素，原来的底层数组放不下的时候，go底层就会把底层数组换一个
	fmt.Printf("s2=%v len(s2)=%d cap(s2)=%d\n", s2, len(s2), cap(s2))
	ss := []string{"广东", "西安", "兰州"}
	s1 = append(s1, ss...) //...表示解构
	fmt.Printf("s1=%v len(s1)=%d cap(s1)=%d\n", s1, len(s1), cap(s1))

	a := []int{1, 2, 3, 4}
	b := a
	a[0] = 100
	fmt.Printf("a=%v,a=%p\n", a, a)
	fmt.Printf("b=%v,b=%p\n", b, b)
	v := []int{1, 2, 3}
	m := make([]int, 3, 3)
	copy(m, v)
	fmt.Printf("v=%v,v=%p\n", v, v) //[1 2 3]
	fmt.Printf("m=%v,m=%p\n", m, m) //[1 2 3]
	m[0] = 1000
	fmt.Println(v) //[1 2 3]
	fmt.Println(m) //[1000 2 3]
}
